package Service;

import Entity.Business;
import Mapper.BusinessMapper;
import Service.BusinessService;
import java.time.LocalDateTime;
import java.util.List;

public class BusinessServiceImpl implements BusinessService {

    private BusinessMapper businessMapper;

    public void setBusinessMapper(BusinessMapper businessMapper) {
        this.businessMapper = businessMapper;
    }

    @Override
    public boolean save(Business business) {
        if (business.getNo() == null) {
            throw new IllegalArgumentException("业务编号不能为空");
        }
        if (business.getCreate_time() == null) {
            business.setCreate_time(LocalDateTime.now());
        }
        return businessMapper.insert(business) > 0;
    }

    @Override
    public boolean delete(Integer id) {
        return businessMapper.deleteById(id) > 0;
    }

    @Override
    public boolean update(Business business) {
        if (business.getId() == null) {
            throw new IllegalArgumentException("更新业务必须指定ID");
        }
        return businessMapper.update(business) > 0;
    }

    @Override
    public Business getById(Integer id) {
        return businessMapper.selectById(id);
    }

    @Override
    public List<Business> getAll() {
        return businessMapper.selectAll();
    }

    @Override
    public List<Business> getByType(String type) {
        return businessMapper.selectByType(type);
    }

    @Override
    public List<Business> getByCustomerName(String customerName) {
        return businessMapper.selectByCustomerName(customerName);
    }
}